package com.ruoyi.financial.controller;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.ruoyi.financial.domain.FxyFinancialEmployee;
import com.ruoyi.financial.util.excel.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.ruoyi.financial.service.IFxyFinancialEmployeeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

import static com.ruoyi.common.security.utils.SecurityUtils.getUsername;

/**
 * 职员表Controller
 * 
 * @author zx
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/financial")
public class FxyFinancialEmployeeController extends BaseController
{
    @Autowired
    private IFxyFinancialEmployeeService fxyFinancialEmployeeService;

    /**
     * 查询职员表列表
     */
    @RequiresPermissions("financial:financial:list")
    @GetMapping("/list")
    public TableDataInfo list(FxyFinancialEmployee fxyFinancialEmployee)
    {
        startPage();
        List<FxyFinancialEmployee> list = fxyFinancialEmployeeService.selectFxyFinancialEmployeeList(fxyFinancialEmployee);
        return getDataTable(list);
    }

    /**
     * 导出职员表列表
     */
    @RequiresPermissions("financial:financial:export")
    @Log(title = "职员表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxyFinancialEmployee fxyFinancialEmployee)
    {
        List<FxyFinancialEmployee> list = fxyFinancialEmployeeService.selectFxyFinancialEmployeeList(fxyFinancialEmployee);
        ExcelUtil<FxyFinancialEmployee> util = new ExcelUtil<FxyFinancialEmployee>(FxyFinancialEmployee.class);
        util.exportExcel(response, list, "职员表数据");
    }

    /**
     * 获取职员表详细信息
     */
    @RequiresPermissions("financial:financial:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fxyFinancialEmployeeService.selectFxyFinancialEmployeeById(id));
    }

    /**
     * 新增职员表
     */
    @RequiresPermissions("financial:financial:add")
    @Log(title = "职员表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxyFinancialEmployee fxyFinancialEmployee)
    {
        return toAjax(fxyFinancialEmployeeService.insertFxyFinancialEmployee(fxyFinancialEmployee));
    }

    /**
     * 修改职员表
     */
    @RequiresPermissions("financial:financial:edit")
    @Log(title = "职员表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxyFinancialEmployee fxyFinancialEmployee)
    {
        return toAjax(fxyFinancialEmployeeService.updateFxyFinancialEmployee(fxyFinancialEmployee));
    }

    /**
     * 删除职员表
     */
    @RequiresPermissions("financial:financial:remove")
    @Log(title = "职员表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fxyFinancialEmployeeService.deleteFxyFinancialEmployeeByIds(ids));
    }

//
//    /**
//     * 导入五险一金设置表数据
//     */
//
//    @RequiresPermissions("financial:financial:importData")
//    @Log(title = "五险一金设置表", businessType = BusinessType.IMPORT)
//    @PostMapping("/importData")
//    public AjaxResult importData(@RequestParam(value = "file") MultipartFile file) throws Exception {
//
//        ExcelUtil<FxyFinancialEmployee> util = new ExcelUtil<>(FxyFinancialEmployee.class);
////        List<FxyFinancialEmployee> socialsecurityList = util.importExcel(file.getInputStream());
//        // 将 MultipartFile 转换为可标记的输入流
//
//        InputStream inputStream = new BufferedInputStream(file.getInputStream());
//        List<FxyFinancialEmployee> socialsecurityList = util.importExcel(inputStream);
//
//        String message = fxyFinancialEmployeeService.importSocialsecurity(socialsecurityList);
//        return success(message);
//    }
//
//    /**
//     * 下载导入模板
//     */
//
//    @PostMapping("/importTemplate")
//    public void importTemplate(HttpServletResponse response) throws Exception {
//        ExcelUtil<FxyFinancialEmployee> util = new ExcelUtil<>(FxyFinancialEmployee.class);
//        util.importTemplateExcel(response, "职员数据");
//    }

}
